;;;;;;;

var form = document.querySelector('form')
console.log(form);
var op = document.querySelectorAll('form p')
var verCode =document.querySelector('form span')
console.log(verCode);
var radio = document.querySelector('form .radio').checked
console.log(radio);
var  arr = [false,false,false,false,false] 

for (let i = 0; i < arr.length-1; i++) {
    op[i].style.visibility = 'hidden'
    
}
 //验证手机号
form.username.onblur=function(){
    var re = /^1[3-9]\d{9}$/
    if(re.test(this.value)){
        arr[0] = true
        op[0].style.visibility = 'hidden'
       
    }else{
        arr[0] = false
        op[0].innerHTML = '手机号格式错误!'
        op[0].style.visibility = 'visible'
     }
 
}
// 验证密码1
form.psw.onblur=function(){
    // 必须是数字和字母组合  不能少于6位
    var re = /^(?!\d+$)(?![a-zA-Z]+$)[0-9a-zA-Z]{6,}$/
    if(re.test(this.value)){
        arr[1] = true
        op[1].style.visibility = 'hidden'
    }else{
        op[1].style.visibility = 'visible'
    }

}

//验证确认密码2
form.repsw.onblur=function(){
    if(this.value==form.psw.value){
        arr[2] = true
        op[2].style.visibility = 'hidden'
    }else{
        arr[2] = false
        op[2].innerHTML = '两次密码输入不一致!'
        op[2].style.visibility = 'visible'
    }
    console.log(arr);
}

//验证 验证码
form.verCode.onblur=function(){
    if(verCode.innerHTML.toLocaleLowerCase() == this.value.toLocaleLowerCase()){
     arr[3] = true
     op[3].style.visibility = 'hidden'
    }else{
     arr[3] = false
     op[3].innerHTML = '验证码错误！'
     op[3].style.visibility = 'visible'
    }
    console.log(arr);
 }

 //同意协议
form.radio.onclick=function(){
    if(radio==true){
        console.log('asd');
     arr[4] = false
 
    }else{
     arr[4] = true
    
    }
    console.log(arr);
 }
 // 注册 当前 所有输入内容都正确 可以注册
form.onsubmit=function(){

    var flag = arr.every(function(item){
        return item
    })

    if(flag){ //可以提交
        // 保存到数组中  数组中有一个对象 对象是用户名和密码
        var  Userarr = []
        var obj = {
            username:form.username.value,
            psw:form.psw.value
        }
        Userarr.push(obj)
        Y.Storage('user',Userarr)
        location.href='./login.html'
        
    }else{ // 不能提交
        alert('输入有误,请检查输入是否完整')   
    }  
    return false //阻止提交
}